/*
 * Copyright (C) 2012 Martin Řehánek
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package cz.mzk.funnylib.api.builders;

import cz.mzk.funnylib.dao.db.LibraryCheckDAOImpl;
import cz.mzk.funnylib.dao.db.LibraryDAOImpl;
import cz.mzk.funnylib.dao.mockup.LibraryDAOMockup;
import cz.mzk.funnylib.entities.Library;
import java.util.Random;


/**
 *
 * @author Martin Řehánek
 */
public class LibraryBuilder extends AbstractBuilder {

    public String buildLibrary(long id) {
        //TODO: nahradit mockup
        Library library = new LibraryDAOMockup().getLibraryById(id);
        return buildLibrary(library);
//      
        //TODO: imlementovat
//        Library library = new LibraryDAOImpl(getJdbcTemplate()).getLibraryById(id);
//        return buildLibrary(library);
        
    }

    public String buildLibrary(Library library) {
        StringBuilder result = new StringBuilder();
        result.append("{");
        result.append("\"").append("id").append("\"").append(":");
        result.append("\"").append(library.getId()).append("\"");
        result.append(",");
        result.append("\"").append("name").append("\"").append(":");
        result.append("\"").append(library.getName()).append("\"");
        result.append(",");
        result.append("\"").append("abbr").append("\"").append(":");
        result.append("\"").append(library.getShortcut()).append("\"");
        result.append(",");
        result.append("\"").append("street").append("\"").append(":");
        result.append("\"").append(library.getStreet()).append("\"");
        result.append(",");
        result.append("\"").append("ZIP").append("\"").append(":");
        result.append("\"").append(library.getPostcode()).append("\"");
        result.append(",");
        result.append("\"").append("city").append("\"").append(":");
        result.append("\"").append(library.getCity()).append("\"");
        result.append(",");
        result.append("\"").append("longitude").append("\"").append(":");
        result.append("\"").append(library.getLon()).append("\"");
        result.append(",");
        result.append("\"").append("latitude").append("\"").append(":");
        result.append("\"").append(library.getLat()).append("\"");
        result.append(",");
        result.append("\"").append("url").append("\"").append(":");
        result.append("\"").append(library.getWeb()).append("\"");
        result.append("}");
        return result.toString();
    }

    public Library mockLibrary(long id) {
        Library result = new Library();
        result.setId(id);
        result.setName("MORAVSKA");
        result.setCity("Brno");
        Random rand = new Random();
        Double lat = 16.593644;
        lat = lat  - rand.nextDouble() * 0.5;
        result.setLat(Double.toString(lat));
        Double lon = 49.208724;
        lon = lon  - rand.nextDouble() * 0.5;
        result.setLon(Double.toString(lon));
        
        result.setPostcode("123");
        result.setShortcut("MZK");
        result.setStreet("Kounicova ");
        result.setWeb("http://www.mzk.cz");
        return result;
    }
}
